package com.etime.shycourse.services.coupons.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shycourse.services.coupons.interfaces.CouponlogServices;
import com.etime.shycourse.dao.CouponlogMapper;
import com.etime.shycourse.dto.CouponlogDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**

 *
 * @author wb
 * @since 2022-03-15
 */
@Service
public class CouponlogServiceImpl implements CouponlogServices {
    @Autowired
    private CouponlogMapper Mapper;

    /**
     * 优惠券使用记录日志 分页
     * <p></p>
     * 可查询的条件有：
     * 优惠劵名模糊搜索 coupontitle
     * 优惠劵使用类型couponlogtype
     * 优惠券使用时间 couponlogtime
     * 优惠券编号 couponno
     *
     * @param pageNum,     第几页       可不传
     * @param pageSize     一页多少数据  可不传
     * @param couponlogDto
     * @return Page<CouponlogDto>
     */
    @Override
    public Page<CouponlogDto> selectCouponUseLogPage(CouponlogDto couponlogDto, Long pageNum, Long pageSize) {
        Page<CouponlogDto> page;
        if (pageNum != null && pageSize != null) {
            page = new Page<> (pageNum, pageSize);
        } else {
            page = new Page<> ();
        }

        if (couponlogDto.getCouponlogusername () != null) {
            couponlogDto.setCouponlogusername ("%" + couponlogDto.getCouponlogusername () + "%");
        }
        if (couponlogDto.getCoupontitle () != null) {
            couponlogDto.setCoupontitle ("%" + couponlogDto.getCoupontitle () + "%");
        }
        return Mapper.selectCouponlogDtoPage (couponlogDto, page);
    }
}
